package com.qaml.mes.device.controller;


import com.earth.output.OutputMessage;
import com.earth.page.PageResponse;
import com.earth.user.AuthSsoContext;
import com.qaml.mes.device.api.CheckUpkeepRecordService;
import com.qaml.mes.device.dto.eqp.*;
import com.qaml.mes.device.vo.eqp.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 检保任务表 前端控制器
 * </p>
 *
 * @author leikai
 * @since 2024-02-27
 */
@Api(tags = "检保任务")
@RestController
@RequestMapping("/checkUpkeepRecord")
public class CheckUpkeepRecordController {

    @Resource
    private CheckUpkeepRecordService checkUpkeepRecordService;

    @ApiOperation(value = "检保记录-列表查询(Web)", notes = "检保记录-列表查询")
    @PostMapping("/checkUpkeepRecordList")
    public PageResponse<CheckUpkeepRecordVO> list(@RequestBody CheckUpkeepRecordListDTO checkUpkeepRecordListDTO) {
        return checkUpkeepRecordService.pageList(checkUpkeepRecordListDTO);

    }

    @ApiOperation(value = "检保任务-检保任务详情 --根据检保任务checkUpkeepRecordId(Web)", notes = "检保任务-检保任务详情")
    @PostMapping("/record/detail")
    public OutputMessage<CheckUpkeepRecordVO> getById(@RequestBody @Validated CheckUpkeepRecordIdReqDTO reqDTO) {
        CheckUpkeepRecordVO checkUpkeepRecordVO = checkUpkeepRecordService.getByCheckUpkeepRecordId(reqDTO.getCheckUpkeepRecordId());
        if (ObjectUtils.isEmpty(checkUpkeepRecordVO)) {
            return OutputMessage.success();
        } else {
            return OutputMessage.success(checkUpkeepRecordService.getByCheckUpkeepRecordId(reqDTO.getCheckUpkeepRecordId()));
        }
    }

    @GetMapping("/homePage/count")
    @ApiOperation(value = "首页-统计(App)", notes = "首页-统计")
    public OutputMessage<HomePageCountVO> getHomePageCount() {
        String currentUserId = AuthSsoContext.getCurrentUserId();
        HomePageCountVO homePageCountVO = checkUpkeepRecordService.countDoing(currentUserId);
        return OutputMessage.success(homePageCountVO);
    }

    /**
     * app检保单-列表查询
     *
     * @param recordAppDTO
     * @return
     */
    @PostMapping("/order/list")
    @ApiOperation(value = "app检保单-列表查询(App)", notes = "app检保单-列表查询")
    public PageResponse<CheckUpkeepRecordAppVO> checkUpkeepOrderList(@RequestBody CheckUpkeepRecordAppDTO recordAppDTO) {
        return checkUpkeepRecordService.orderList(recordAppDTO);
    }

    @PostMapping("/checkUpkeepRecordDetailApp")
    @ApiOperation(value = "app检保单-查询详情(App)", notes = "app检保单-查询详情")
    public OutputMessage<CheckUpkeepRecordAppVO> getCheckUpkeepRecordDetailApp(@RequestBody @Validated CheckUpkeepRecordIdDTO checkUpkeepRecordId) {
        CheckUpkeepRecordAppVO checkUpkeepRecordAppVO = checkUpkeepRecordService.getCheckUpkeepRecordDetailApp(checkUpkeepRecordId);
        return OutputMessage.success(checkUpkeepRecordAppVO);
    }

    /**
     * 检保提交
     *
     * @return
     */
    @PostMapping("/checkUpkeep/commit")
    @ApiOperation(value = "检保提交(App)", notes = "检保提交")
    public OutputMessage<String> checkUpkeepCommit(@RequestBody CheckUpkeepRecordDTO checkUpkeepRecordDTO) {
        checkUpkeepRecordService.checkUpkeepCommit(checkUpkeepRecordDTO);
        return OutputMessage.success("提交成功！");
    }

    /**
     * 检保提交维修
     *
     * @return
     */
    @PostMapping("/checkUpkeep/commitRepair")
    @ApiOperation(value = "检保提交维修(App)", notes = "检保提交维修")
    public OutputMessage<String> checkUpkeepCommitRepair(@RequestBody CheckUpkeepRecordDTO checkUpkeepRecordDTO) {
        checkUpkeepRecordService.checkUpkeepCommitRepair(checkUpkeepRecordDTO);
        return OutputMessage.success("提交成功！");
    }

    /**
     * 检保记录复核提交
     *
     * @return
     */
    @PostMapping("/recheckCommit")
    @ApiOperation(value = "检保记录复核提交(App)", notes = "检保记录复核提交")
    public OutputMessage<String> recheckCommit(@RequestBody @Validated RecheckCommitDTO recheckCommitDTO) {
        checkUpkeepRecordService.recheckCommit(recheckCommitDTO);
        return OutputMessage.success("提交成功！");
    }

    /**
     * 检保记录复核驳回
     *
     * @return
     */
    @PostMapping("/recheckTurnDown")
    @ApiOperation(value = "检保记录复核驳回(App)", notes = "检保记录复核驳回")
    public OutputMessage<String> recheckTurnDown(@RequestBody @Validated CheckUpkeepRecordTurnDownReqDTO turnDownReqDTO) {
        checkUpkeepRecordService.recheckTurnDown(turnDownReqDTO);
        return OutputMessage.success("驳回成功！");
    }


    /**
     * 归档提交
     *
     * @param archiveCommitDTO
     * @return
     */
    @PostMapping("/archiveCommit")
    @ApiOperation(value = "归档提交(App)", notes = "归档提交")
    public OutputMessage<String> archiveCommit(@RequestBody @Validated ArchiveCommitDTO archiveCommitDTO) {
        checkUpkeepRecordService.archiveCommit(archiveCommitDTO);
        return OutputMessage.success("提交成功！");
    }

    /**
     * 归档驳回
     *
     * @param archiveTurnDownDTO
     * @return
     */
    @PostMapping("/archiveTurnDown")
    @ApiOperation(value = "归档驳回(App)", notes = "归档驳回")
    public OutputMessage<String> archiveTurnDown(@RequestBody @Validated ArchiveTurnDownDTO archiveTurnDownDTO) {
        checkUpkeepRecordService.archiveTurnDown(archiveTurnDownDTO);
        return OutputMessage.success("驳回成功！");
    }

    /**
     * 检保记录快速归档
     *
     * @return
     */
  /*  @PostMapping("/checkUpkeep/fastArchive")
    @ApiOperation(value = "检保记录快速归档(App)", notes = "检保记录快速归档")
    public OutputMessage<String> checkUpkeepArchive(@RequestBody CheckUpkeepArchiveDTO checkUpkeepArchiveDTO) {
        checkUpkeepRecordService.checkUpkeepArchive(checkUpkeepArchiveDTO);
        return OutputMessage.success("归档成功！");
    }*/

    /**
     * 点检归档列表
     */
    @PostMapping("/checkArchivelist")
    @ApiOperation(value = "点检归档列表(App)", notes = "点检归档列表")
    public OutputMessage<CheckArchiveVO> checkArchiveList(@RequestBody CheckUpkeepArchiveDTO checkUpkeepArchiveDTO) {
        String yearMonth = checkUpkeepArchiveDTO.getYearMonth();
        CheckArchiveVO checkArchiveVO = checkUpkeepRecordService.checkArchiveList(yearMonth);
        checkArchiveVO.setYearMonth(yearMonth);
        return OutputMessage.success(checkArchiveVO);
    }

    /**
     * 保养归档列表
     *
     * @return
     */
    @PostMapping("/upkeepArchiveList")
    @ApiOperation(value = "保养归档列表(App)", notes = "保养归档列表")
    public OutputMessage<List<UpkeepArchiveVO>> upkeepArchiveList(@RequestBody CheckUpkeepArchiveDTO checkUpkeepArchiveDTO) {
        String yearMonth = checkUpkeepArchiveDTO.getYearMonth();
        List<UpkeepArchiveVO> upkeepArchiveVOList = checkUpkeepRecordService.upkeepArchiveList(yearMonth);
        return OutputMessage.success(upkeepArchiveVOList);
    }


}
